<template>
	<view class="popupshare__content">
		<image src="/static/img/close.png" class="popupshare__close2" @tap.stop="$emit('close')" />
		<view class="sharetypecontent">
			<view class="sharetypecontent-f1" @tap="shareapp" v-if="platform == 'app'">
				<image class="sharetypecontent-f1-img" :src="pre_url+'/static/img/sharefriends.png'" />
				<text class="sharetypecontent-f1-t1">分享给好友</text>
			</view>
			<view class="sharetypecontent-f1" @tap="sharemp" v-else-if="platform == 'mp'">
				<image class="sharetypecontent-f1-img" :src="preUrl+'/static/img/sharefriends.png'" />
				<text class="sharetypecontent-f1-t1">分享给好友</text>
			</view>
			<!-- <view class="sharetypecontent-f1" @tap="sharemp" v-else-if="platform == 'h5'">
				<image class="sharetypecontent-f1-img" :src="pre_url+'/static/img/sharefriends.png'" />
				<text class="sharetypecontent-f1-t1">分享给好友</text>
			</view> -->
			<button class="sharetypecontent-f1" open-type="share" v-else-if="platform != 'h5'">
				<image class="sharetypecontent-f1-img" :src="preUrl+'/static/img/sharefriends.png'" />
				<text class="sharetypecontent-f1-t1">分享给好友</text>
			</button>
			<view class="sharetypecontent-f2" @tap="$emit('poster')">
				<image class="sharetypecontent-f2-img" src="/static/img/sharepic.png" />
				<text class="sharetypecontent-f2-t1">生成分享图片</text>
			</view>
		</view>
	</view>
</template>

<script>
	const app = getApp();
	
	export default {
		props: {
			current: Object,
		},
		data() {
			return {
				platform: app.globalData.platform,
				preUrl: app.globalData.pre_url,
			}
		},
		methods: {
			shareapp() {
				const videoinfo = this.current
				uni.showActionSheet({
					itemList: ['发送给微信好友', '分享到微信朋友圈'],
					success: (res) => {
						if (res.tapIndex >= 0) {
							const scene = 'WXSceneSession';
							if (res.tapIndex == 1) {
								scene = 'WXSenceTimeline';
							}
							const sharedata = {};
							sharedata.provider = 'weixin';
							sharedata.type = 0;
							sharedata.scene = scene;
							sharedata.title = videoinfo.name;
							sharedata.summary = videoinfo.description;
							sharedata.href = app.globalData.pre_url + '/h5/' + app.globalData.aid +
								'.html#/activity/shortvideo/detail?scene=id_' + videoinfo.id + '-pid_' +
								app.globalData.mid;
							sharedata.imageUrl = videoinfo.coverimg;
							const sharelist = app.globalData.initdata.sharelist;
							if (sharelist) {
								for (var i = 0; i < sharelist.length; i++) {
									if (sharelist[i]['indexurl'] == '/activity/shortvideo/detail') {
										sharedata.title = sharelist[i].title;
										sharedata.summary = sharelist[i].desc;
										sharedata.imageUrl = sharelist[i].pic;
										if (sharelist[i].url) {
											var sharelink = sharelist[i].url;
											if (sharelink.indexOf('/') === 0) {
												sharelink = app.globalData.pre_url + '/h5/' + app
													.globalData.aid + '.html#' + sharelink;
											}
											if (app.globalData.mid > 0) {
												sharelink += (sharelink.indexOf('?') === -1 ? '?' : '&') +
													'pid=' + app.globalData.mid;
											}
											sharedata.href = sharelink;
										}
									}
								}
							}
							uni.share(sharedata);
						}
					}
				});
			},
			sharemp() {
				app.error('点击右上角发送给好友或分享到朋友圈');
				this.$emit('close')
			},
		}
	}
</script>

<style lang="scss" scoped>
	.popupshare__content {
		position: absolute;
		bottom: 0;
		left: 0;
		right: 0;
		z-index: 999999;
		width: 750rpx;
		height: 280rpx;
		padding: 20rpx 0;
		background: #fff;
		display: flex;
	}
	
	.popupshare__close2 {
		position: absolute;
		top: 10rpx;
		right: 10rpx;
		z-index: 1000;
		width: 50rpx;
		height: 50rpx;
		padding: 10rpx;
	}
	.sharetypecontent {
		flex: 1;
		width: 710rpx;
		height: 250rpx;
		margin: 0 20rpx;
		display: flex;
		flex-direction: row;
		padding: 50rpx;
	}
	
	.sharetypecontent-f1 {
		flex: 1;
		display: flex;
		flex-direction: column;
		align-items: center;
		background: #fff;
		font-size: 24rpx;
		border: 0
	}
	
	.sharetypecontent button::after {
		border: 0
	}
	
	.sharetypecontent-f1-img {
		width: 90rpx;
		height: 90rpx;
		padding: 0;
		margin: 0
	}
	
	.sharetypecontent-f1-t1 {
		font-size: 24rpx;
		color: #111111;
		height: 60rpx;
		line-height: 60rpx
	}
	
	.sharetypecontent-f2 {
		flex: 1;
		display: flex;
		flex-direction: column;
		align-items: center
	}
	
	.sharetypecontent-f2-img {
		width: 90rpx;
		height: 90rpx;
	}
	
	.sharetypecontent-f2-t1 {
		font-size: 24rpx;
		color: #111111;
		height: 60rpx;
		line-height: 60rpx
	}
</style>